package cjlu.ea.h.service.impl;

import cjlu.ea.h.common.TimeUtils;
import cjlu.ea.h.entity.ByszgshbLsb;
import cjlu.ea.h.mapper.F101ByszgshbLsbMapper;
import cjlu.ea.h.service.F101ByszgshbLsbService;
import cjlu.ea.h.service.SUserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;


import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author testjava
 * @since 2022-06-07
 */
@Service
@Slf4j
public class F101ByszgshbLsbServiceImpl extends ServiceImpl<F101ByszgshbLsbMapper, ByszgshbLsb> implements F101ByszgshbLsbService {
    @Autowired
    F101ByszgshbLsbMapper f101ByszgshbLsbMapper;


    @Override
    public List<Object> getbyssj(ByszgshbLsb byszgshbLsb, Long current, Long limit ,String role) {
        QueryWrapper<ByszgshbLsb> wrapper = new QueryWrapper<>();

        //条件查询
        if(!StringUtils.isEmpty(byszgshbLsb.getXh())){//学号
            wrapper.likeRight("xh",byszgshbLsb.getXh());
        }
        if(byszgshbLsb.getXm()!=null){//姓名
            wrapper.likeRight("xm",byszgshbLsb.getXm());
        }
        if(byszgshbLsb.getXy()!=null){//学院
            wrapper.likeRight("xy",byszgshbLsb.getXy());
        }
        if(byszgshbLsb.getBh()!=null){//班级
            wrapper.likeRight("bh",byszgshbLsb.getBh());
        }
        if(byszgshbLsb.getZyh()!=null){//专业
            wrapper.likeRight("bh",byszgshbLsb.getBh());
        }
        if(byszgshbLsb.getBz()!=null){//状态
            wrapper.eq("bz",byszgshbLsb.getBz());
        }
        if(byszgshbLsb.getByzg()!=null){//毕业资格
            wrapper.eq("byzg",byszgshbLsb.getByzg());
        }
        if(byszgshbLsb.getXwzg()!=null){//学位资格
            wrapper.eq("xwzg",byszgshbLsb.getXwzg());
        }
        if(!StringUtils.isEmpty(role)){//权限控制
            wrapper.eq("xy",role);
        }

        //分页显示
        Page<ByszgshbLsb> page = new Page<>(current,limit);
        baseMapper.selectPage(page,wrapper);

        //数据查询获取
        List<ByszgshbLsb> list = page.getRecords();
        Long total = page.getTotal();
        List<Object> res = new ArrayList<>();
        res.add(list);
        res.add(total);

        log.info("ServiceImpl--F101 getbyssj(),查询毕业生数据成功.....");


        return res;
    }

    @Override
    public void SaveOrUpdateByXh(List<ByszgshbLsb> list) {
        f101ByszgshbLsbMapper.savaOrUpdateBatchByXh(list);
    }


}
